package demo01;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, 2000); // 设置年份
        calendar.set(Calendar.MONTH, Calendar.FEBRUARY); // 设置月份为二月
        int daysInFebruary = calendar.getActualMaximum(Calendar.DATE); // 获取该年二月的实际天数
        System.out.println(daysInFebruary == 29 ? "闰年" : "平年");
    }

    private static void test03() {
        test04();
    }

    private static void test04() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        System.out.println(calendar.get(Calendar.YEAR));
        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
        System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
        System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
        System.out.println(calendar.get(Calendar.DATE));
        calendar.set(2000, Calendar.FEBRUARY, 1);
        calendar.set(Calendar.YEAR, 2004);
        System.out.println(calendar.get(Calendar.YEAR));
    }

    private static void test02() throws ParseException {
        // 日期转字符串
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
        String formatted = dateFormat.format(date);
        System.out.println(formatted);
        Date date1 = dateFormat.parse(new Scanner(System.in).nextLine());
        System.out.println(date1);
    }

    private static void test01() {
        Date date = new Date();
        System.out.println(date);
        System.out.println(new Date(1000));
        System.out.println(new Date(System.currentTimeMillis()));
    }
}
